package com.jonniespratley.generators.mysql.data
{
	import mx.collections.ArrayCollection;
	import mx.utils.UIDUtil;

	[Bindable]
	public class Database extends Object
	{
		public var aDBName:String;
		public var aDatabase:String;
		public var aType:String;
		public var aIcon:String;
		public var aData:String;
		public var aTables:ArrayCollection;
		public var databaseUUID:String;

		public function  Database( obj:Object = null )
		{
			if ( obj != null )
			{
				this.aDBName = obj['aDatabase'];
				this.aDatabase = obj['aDatabase'];
				this.aType = obj['aType'];
				this.aData = obj['aData'];
				this.aIcon = obj['aIcon'];

				//set the fields comming back as an Array
				var tempArray:Array = obj['aTables'] as Array;

				//create a temp arraycollection so return to the aFields
				var tempAc:ArrayCollection = new ArrayCollection();

				//loop through every string in the fields array
				for ( var s:String in tempArray )
				{
					//for each object add it to the temp collection
					tempAc.addItem( new Table( tempArray[s] ) );
				}
				//set the array collection to the build one of value objects
				this.aTables = tempAc;

			}
		}

		public function get label():String
		{
			return aDatabase;
		}

		public function get children():Array
		{
			return aTables.toArray();
		}

		public function get data():Object
		{
			return aType;
		}

		public function get type():String
		{
			return 'database';
		}

		public function createUUID():String
		{
			return UIDUtil.createUID();
		}

	}
}